/**
 * 详情对话框
 */
var FactoryVideoInfoDlg = {
    data: {
        factoryId: "",
        title: "",
        description: "",
        url: "",
        image: "",
        status: "",
        weigh: "",
        createTime: "",
        updateTime: "",
        recordStatus: ""
    },
    editor:null,
};

layui.use(['form', 'admin', 'ax','simTool','tableSelect'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;
    var simTool = layui.simTool;
    var tableSelect = layui.tableSelect;
    //让当前iframe弹层高度适应
    //admin.iframeAuto();


    /**
     * 上传图片
     */
    var sim = new simTool("/upload","#picBox");
    sim.uploadImg()
    //初始化编辑器
    var E = window.wangEditor;
    var editor = new E('#description_toolbar', '#description_text');
    // 将图片大小限制为 2M
    editor.customConfig.uploadImgMaxSize = 50 * 1024 * 1024;
    editor.customConfig.uploadImgServer =Feng.ctxPath+'/upload/wang'; //'common/batch/imgUpdate';
    editor.customConfig.uploadFileName = 'file';
    editor.customConfig.customAlert = function (info){
        // info 是需要提示的内容
        alert('上传失败，请重试：' + info);
    }
    editor.create();
    FactoryVideoInfoDlg.editor = editor;


    //表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        var ajax = new $ax(Feng.ctxPath + "/factoryVideo/addItem", function (data) {
            Feng.success("添加成功！");

            //传给上个页面，刷新table用
            admin.putTempData('formOk', true);

            //关掉对话框
            admin.closeThisDialog();
        }, function (data) {
            Feng.error("添加失败！" + data.responseJSON.message)
        });
        ajax.set("description",editor.txt.html())
        ajax.set(data.field);
        ajax.start();
    });

    /**
     * 农场的选择
     */
    tableSelect.render({
        elem: '#factoryName',	//定义输入框input对象 必填
        checkedKey: 'id', //表格的唯一建值，非常重要，影响到选中状态 必填
        searchKey: 'name',	//搜索输入框的name值 默认keyword-
        searchPlaceholder: '农场名',	//搜索输入框的提示文字 默认关键词搜索
        table: {	//定义表格参数，与LAYUI的TABLE模块一致，只是无需再定义表格elem
            url:Feng.ctxPath+'/factory/factoryList',
            cols: [[
                {type: 'radio'},
                {field: 'id', title: 'id'},
                {field: 'name', sort: true, align:'center',title: '农场名'},
            ]]
        },
        done: function (elem, data) {
            //选择完后的回调，包含2个返回值 elem:返回之前input对象；data:表格返回的选中的数据 []
            //拿到data[]后 就按照业务需求做想做的事情啦~比如加个隐藏域放ID...
            console.log(data.data.length)
            console.log(data.data[0].id)
            //alert(data[0][0].id)
            // elem.val(data.data);
            elem.parent().find("#factoryId").val(data.data[0].id);
            elem.parent().find("#factoryName").val(data.data[0].name);
        }
    })


});